package com.hssy.wululuaplan.controller;


import com.hssy.wululuaplan.common.Result;
import com.hssy.wululuaplan.form.CourseScheduleForm;
import com.hssy.wululuaplan.service.CourseScheduleService;
import com.hssy.wululuaplan.vo.ClassRecordVo;
import com.hssy.wululuaplan.vo.CourseScheduleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  课程计划 前端控制器
 * </p>
 *
 * @author Mr.Hongtao
 * @since 2024-02-28
 */
@Api(tags = "课程计划")
@RestController
@RequestMapping("/wululuaplan/course-schedule")
public class CourseScheduleController {

    @Resource(name = "courseSchedule")
    private CourseScheduleService courseScheduleService;

    @ApiOperation("查询全部计划")
    @GetMapping("/findAll")
    public Result<CourseScheduleVo> findAll() {
        CourseScheduleVo vo = courseScheduleService.findAll();
        return Result.success(vo);
    }

    @ApiOperation("根据id查询课程计划")
    @GetMapping("/findById")
    public Result<ClassRecordVo> findById(@RequestParam("id") Integer id) {
        ClassRecordVo vo = courseScheduleService.findById(id);
        return Result.success(vo);
    }
    @ApiOperation("新增课程计划")
    @PostMapping("/create")
    public Result<String> create(@RequestBody CourseScheduleForm form) {
        courseScheduleService.create(form);
        return Result.success();
    }

    @ApiOperation("修改课程计划")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody CourseScheduleForm form) {
        courseScheduleService.edit(form);
        return Result.success();
    }

    @ApiOperation("删除课程计划")
    @PostMapping("/delete")
    public Result<String> delete(Integer id) {
        int code = courseScheduleService.delete(id);
        if (code == -200) {
            return Result.error(-200,"已有签到记录，不可以修改该课程计划");
        }else {
            return Result.success();
        }
    }

}

